package net.yunzhanyi.client.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author bestct
 * @date 2022/10/2
 * @type 类
 */
public class AjaxUtils {
    /**
     * 判断网络请求是否为ajax
     *
     * @param request
     * @return
     */
    public static boolean isAjax(HttpServletRequest request) {
        String contentTypeHeader = request.getHeader("Content-Type");
        String acceptHeader = request.getHeader("Accept");
        String xRequestedWith = request.getHeader("X-Requested-With");
        return (contentTypeHeader != null && contentTypeHeader.contains("application/json"))
                || (acceptHeader != null && acceptHeader.contains("application/json"))
                || "XMLHttpRequest".equalsIgnoreCase(xRequestedWith);
    }

}
